package com.lglin.common.utils.bean;
import org.springframework.beans.BeanUtils;
import java.util.List;
import static java.util.stream.Collectors.toList;
public class BeanCopyUtil {

    public static <T> T copy(final Object source, final Class<T> clazz) {
        if (source == null) {
            return null;
        }
        try {
            T t = clazz.newInstance();
            BeanUtils.copyProperties(source, t);
            return t;
        } catch (InstantiationException e) {
           e.printStackTrace();
        } catch (IllegalAccessException e) {
           e.printStackTrace();
        }
        return null;
    }

    public static <E, V> List<V> copyListToList(List<E> source, Class<V> clazz) {
        return source.stream().map(pojo -> copy(pojo, clazz)).collect(toList());
    }

}
